<template>
	<view class="">
		<!--  -->
		<ben></ben>
		<!--  -->
		<view class="background_f">
			<uni-segmented-control :current="current" :values="tabList" @clickItem="onClickItem" styleType="text"
				activeColor="#FFAD4C"></uni-segmented-control>
		</view>
		<view class="min30">
			<u-search placeholder="日照香炉生紫烟" bgColor="#fff" v-model="keyword"></u-search>
		</view>
		<view class="empty" style="margin-top: 300rpx;" v-if="list.length == 0">
			<u-empty mode="data" icon="https://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
		<view class="" v-else>

			<view class="column rad1 min30_rl pad20 background_f" style="margin-top: 20rpx;"
				v-for="(item,index) in list" :key="index">
				<view class="row just_cont_spacebet size28 col0 font500">
					订单编号：{{ item.order_no }}
					<view class="font600" style="color: #FE3C3C;" v-if="item.order_status == 3">
						已完成
					</view>
					<view class="font600" style="color: #FE3C3C;" v-if="item.order_status == 4">
						已取消
					</view>
					<view class="font600" style="color: #FE3C3C;" v-if="item.order_status == 5">
						已同意取消
					</view>
				</view>
				<view class="mintop20 row">
					<view style="width: 25%;">
						<image :src="item.order_product.goods_cover" mode="" style="width: 95%;height: 130rpx;"></image>
					</view>
					<view class="disflex align_item_c just_cont_flexend size22 font500 col6" style="width: 16%;">
						共{{ item.total_specs_num }}件
						<u-icon name="arrow-right" color="#666" size="11"></u-icon>
					</view>
				</view>
				<view class="minauto minright0 mintop30 font600" style="width: 240rpx;">
					<u-button text="订单详情" shape="circle" customStyle="color: #333;" color="#FFAD4C" hairline="false"
						size="small"
						@click="$jump.nav('/indexpackage/store/orders_info?id=' + item.id + '&uid=' + item.user_id + '&total_price=' + item.shop_total_price +
						 '&create_time=' + item.create_time + '&order_status=' + item.order_status)"></u-button>
				</view>
			</view>
			<view style="padding: 40rpx 0;"><u-loadmore :status="status" /></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: ['全部', '已完成', '已取消'],
				current: 0,
				page: 1,
				status: 'nomore',
				loadmore: [],
				list: [],
			}
		},
		onLoad(op) {
			this.current = op.current
			console.log(op.current);
		},
		onShow() {
			//当前页面展示的时候他就执行该生命周期
			this.user_id = uni.getStorageSync('user_id');
			const token = uni.getStorageSync('token');
			if (token) {
				//如果存在token
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 10 // 滚动动画时长，默认300ms
				});
				this.page = 1
				this.getOrderList()
				//按正常逻辑来讲 登录成功 我们是不是需要向服务器获取用户的信息？
				//那么我们一起来获取用户信息
			} else {

				uni.showToast({
					title: '您还未登录，正在前往登录',
					icon: 'none'
				})
				setTimeout(function() {
					uni.navigateTo({
						url: "/mypackage/user/login"
					})
				}, 1000)
			}
		},
		onReachBottom() {
			if (this.page < 0) return;
			this.status = 'loading';
			this.page = ++this.page
			this.getOrderList()
			setTimeout(() => {
				console.log(this.loadmore);
				if (this.loadmore.length == 0) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		},
		methods: {
			async getOrderList() {
				var order_status = ''
				if (this.current == 0) {
					order_status = ''
				} else if (this.current == 1) {
					order_status = 3
				} else {
					order_status = 4
				}
				let {
					code,
					message,
					data
				} = await this.$com.fetchGet("shop/shop_order_list/" + this.user_id, {
					order_status: order_status,
					page: this.page
				})
				if (code == 200) {
					if (this.page != 1) {
						this.loadmore = data.items
						for (var i = 0; i < data.items.length; i++) {
							this.list.push(data.items[i]); // 加载的数据追加在上一页后面
						}
					} else {
						this.loadmore = data.items
						this.list = data.items
					}
				} else if (code == 500) {
					this.list = data
					this.loadmore = data
				} else {
					console.log(message);
				}
			},
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
				this.getOrderList()
			}
		}
	}
</script>

<style scoped lang="less">

</style>